package com.lty.jeeg.server.modules.fas.dao;

import java.util.List;
import java.util.Map;

import com.lty.jeeg.server.modules.fas.dto.GoodsDTO;
import com.lty.jeeg.server.modules.fas.export.GoodsExportEntity;
import com.lty.jeeg.server.modules.fas.model.Goods;
import com.lty.jeeg.server.modules.fas.vo.GoodsVO;
import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Repository;

/**
 * @author : LTY
 * @date : 2019-01-18 16:37:02
 * Description : 商品
 */
@Mapper
@Repository
public interface GoodsDao {

    /**
     * 根据ID获取
     * @param id ID
     * @return bean
     */
    @Select("select " +
            "t.*, gc.name AS categoryName " +
            "from fas_goods t " +
            "left join fas_goods_category gc on t.category = gc.id " +
            "where t.isDeleted = 0 AND t.id = #{id}")
    GoodsDTO getById(Long id);

    @Select("select " +
            "t.*, gc.name AS categoryName " +
            "from fas_goods t " +
            "left join fas_goods_category gc on t.category = gc.id " +
            "where t.isDeleted = 0 AND t.code = #{code}")
    GoodsDTO getByCode(String code);

    /**
     * 删除
     * @param id ID
     * @return 1/0
     */
    @Delete("update fas_goods set isDeleted = '1' where id = #{id}")
    int delete(Long id);

    /**
     * 修改
     * @param goods ID
     * @return 1/0
     */
    int update(Goods goods);

    /**
     * 保存
     * @param goods bean
     * @return ID
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into fas_goods(name, code, category, specification, unit, unitPrice, isCommon, isConsumables, remark, createBy, updateBy, isDeleted, screenshotPath) values(#{name}, #{code}, #{category}, #{specification}, #{unit}, #{unitPrice}, #{isCommon}, #{isConsumables}, #{remark}, #{createBy}, #{updateBy}, #{isDeleted}, #{screenshotPath})")
    Long save(Goods goods);

    /**
     * 计数
     * @param params 筛选条件
     * @return 总数
     */
    int count(@Param("params") Map<String, Object> params);

    /**
     * 列表
     * @param params 筛选条件
     * @param offset 页码
     * @param limit 分页数目
     * @return beanList
     */
    List<GoodsVO> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    /**
     * 列表导出
     * @param goodsDTO 筛选条件
     * @return beanList
     */
    List<GoodsExportEntity> getExportDatas(GoodsDTO goodsDTO);

}
